// pages/regist/regist.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    password:"",
    rpassword:""
  },

  username:function(e){
    var name = e.detail.value;
    this.setData({name:name});
  },
  userpwd:function(e){
    var password = e.detail.value;
    this.setData({password:password});
  },
  ruserpwd:function(e){
    var rpassword = e.detail.value;
    this.setData({rpassword:rpassword});
  },
  regist:function(){
    // console.log(this.data.name);
    // console.log(this.data.password);
    // console.log(this.data.rpassword);
    if(this.data.password!==this.data.rpassword){
      wx.showToast({
        title: '两次密码不一样',
        icon:'error',
        duration:2000
      })
      return;
    }

    if(this.data.password==null||this.data.rpassword==null){
      wx.showToast({
        title: '请输入密码',
        icon:'error',
        duration:2000
      })
      return;
    }

    wx.request({
      'url': 'https://www.liahnu.top/apis/user/register',
      method:"POST",
      data:{
        phone:this.data.name,
        password:this.data.password
      },
      success:function(res){
        // console.log(res.data);
        if(res.data.success===true){
          wx.showToast({
            title: "注册成功",
            icon:'success',
            duration:2000
          })
        }else{
          wx.showToast({
            title: res.data.errorMsg,
            icon:'error',
            duration:2000
          })
        }
      },
      fail:function(res){
        wx.showToast({
          title: '系统错误，请稍后重试',
          icon: 'error',
          duration: 2000
        })
      }
    })
  }
})
